﻿using System;
using System.Collections;
using System.Web;
using System.IO;
using Whir.Common.WebHelper;
using System.Text;

public partial class Whir_System_Module_Config_RedirectConfig : System.Web.UI.Page
{
    protected string path;
    protected void Page_Load(object sender, EventArgs e)
    {
        path = Server.MapPath("~/xml/RedirectConfig.xml");
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        if (File.Exists(path))
        {
            using (StreamReader sr = File.OpenText(path))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    TextBox1.Text += s;
                }
            }
        }
        else
        {
            JsHelper.Alert(Page, "配置文件丢失，加载配置文件失败！");
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
            {
                sw.WriteLine(TextBox1.Text);
            }
            JsHelper.redirect(Page, "配置已保存！", "RedirectConfig.aspx");
        }
        catch (IOException ex)
        {
            JsHelper.Alert(Page, ex.Message);
        }
    }
}
